#include "idlethread.h"

idleThread::idleThread(QTableWidget *tw,UINT16 *db)
{
    this->table=tw;
    this->db=db;

}

QList<InputConfigs *> *idleThread::getInputs() const
{
    return inputs;
}

void idleThread::setInputs(QList<InputConfigs *> *value)
{
    inputs = value;
}

QList<OutputConfigs *> *idleThread::getOutputs() const
{
    return outputs;
}

void idleThread::setOutputs(QList<OutputConfigs *> *value)
{
    outputs = value;
}

void idleThread::run()
{
    QIcon down_c(QString::fromUtf8(":/image/down_c.ico"));
    QIcon down_b(QString::fromUtf8(":/image/down_b.ico"));
    QIcon up_c(QString::fromUtf8(":/image/update_c.ico"));
    QIcon empty(QString::fromUtf8(":/image/empty.ico"));
    while(1)
    {
        for(int i=0;i<50;i++)
        {
            for(int j=0;j<10;j++)
            {
                if(table->item(i,j)==NULL)
                    table->setItem(i,j,new QTableWidgetItem(QString::number(db[i*10+j])));
                else
                    table->item(i,j)->setData(0,QString::number(db[i*10+j]));

            }
        }
        for(int i=0;i<inputs->count();i++)
        {
            if((*inputs)[i]->getConnect()>0)
            {
                //inputs[i]->listIcon->setIcon(down_c);
                emit changeIcon((*inputs)[i]->listIcon,down_c);
                (*inputs)[i]->setConnect(0);
                msleep(100);
            }
            else
            {
                //inputs[i]->listIcon->setIcon(empty);
                emit changeIcon((*inputs)[i]->listIcon,empty);
                msleep(100);

            }
        }
        for(int i=0;i<outputs->count();i++)
        {
            if((*outputs)[i]->getConnect()>0)
            {
                //outputs[i]->listIcon->setIcon(up_c);
                emit changeIcon((*outputs)[i]->listIcon,up_c);
                (*outputs)[i]->setConnect(0);
                msleep(100);
            }
            else
            {
                //outputs[i]->listIcon->setIcon(empty);
                emit changeIcon((*outputs)[i]->listIcon,empty);
                msleep(100);
            }
        }
        msleep(100);
    }

}
